<?php

namespace App\Admin\Controllers\Game;

use App\Admin\Constant\GameConst;
use App\Admin\Controllers\Controller;
use App\Admin\Filters\Game\GameDeleteFilter;
use App\Admin\Filters\GameFilter;
use App\Admin\Models\Game\Game;
use App\Admin\Models\Game\GameCategory;
use App\Admin\Models\Game\GameDelete;
use App\Admin\Models\Game\GameGroup;
use App\Admin\Requests\Game\GameDeleteRequest;
use App\Admin\Resources\Game\GameDeleteResource;
use Illuminate\Http\Request;

class GameDeleteController extends Controller
{
    public function index(GameFilter $filter)
    {
        $type = \request()->input('gameType');
        if($type==3){
            $gameDeletes = GameCategory::query()->filter($filter)->where(['is_delete'=>1])->paginate();
        }else if($type==2){
            $gameDeletes = GameGroup::query()->filter($filter)->where(['is_delete'=>1])->paginate();
        }else{
            $gameDeletes = Game::query()->filter($filter)->where(['is_delete'=>1])->paginate();
        }



        return $this->ok(GameDeleteResource::collection($gameDeletes));
    }


    public function update(GameDeleteRequest $request,$id)
    {
        $inputs = $request->validated();
        $type = $request->input('gameType');
        if($type==3){
            $res = GameCategory::query()->where('id',$id)->update($inputs);
        }else if($type==2){
            $res = GameGroup::query()->where('id',$id)->update($inputs);
        }else{
            $inputs['updated_at'] = time();

            $res = Game::query()->where('id',$id)->update($inputs);
        }

        if(!$res){
            return $this->errorMessage(GameConst::GAME_DELETE_RECOVER_FAIL);
        }
        return $this->created(GameConst::GAME_DELETE_RECOVER_SUCCESS);
    }

    public function  recover(){


        var_dump(1);
    }



}
